{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Using a regression neural network to predict housing prices in Hyderabad"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "from tensorflow import keras\n",
    "\n",
    "# Setting random seeds to get reproducible results\n",
    "np.random.seed(0)\n",
    "import tensorflow as tf\n",
    "tf.random.set_seed(1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Loading and preprocessing the dataset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Price</th>\n",
       "      <th>Area</th>\n",
       "      <th>Location</th>\n",
       "      <th>No. of Bedrooms</th>\n",
       "      <th>Resale</th>\n",
       "      <th>MaintenanceStaff</th>\n",
       "      <th>Gymnasium</th>\n",
       "      <th>SwimmingPool</th>\n",
       "      <th>LandscapedGardens</th>\n",
       "      <th>JoggingTrack</th>\n",
       "      <th>...</th>\n",
       "      <th>LiftAvailable</th>\n",
       "      <th>BED</th>\n",
       "      <th>VaastuCompliant</th>\n",
       "      <th>Microwave</th>\n",
       "      <th>GolfCourse</th>\n",
       "      <th>TV</th>\n",
       "      <th>DiningTable</th>\n",
       "      <th>Sofa</th>\n",
       "      <th>Wardrobe</th>\n",
       "      <th>Refrigerator</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>6968000</td>\n",
       "      <td>1340</td>\n",
       "      <td>Nizampet</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>29000000</td>\n",
       "      <td>3498</td>\n",
       "      <td>Hitech City</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>6590000</td>\n",
       "      <td>1318</td>\n",
       "      <td>Manikonda</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5739000</td>\n",
       "      <td>1295</td>\n",
       "      <td>Alwal</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5679000</td>\n",
       "      <td>1145</td>\n",
       "      <td>Kukatpally</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2513</th>\n",
       "      <td>11000000</td>\n",
       "      <td>1460</td>\n",
       "      <td>Nacharam</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>...</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2514</th>\n",
       "      <td>26000000</td>\n",
       "      <td>1314</td>\n",
       "      <td>Manikonda</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>...</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2515</th>\n",
       "      <td>13300000</td>\n",
       "      <td>2625</td>\n",
       "      <td>Madhapur</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>...</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2516</th>\n",
       "      <td>10800000</td>\n",
       "      <td>2050</td>\n",
       "      <td>Hitech City</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>...</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2517</th>\n",
       "      <td>10400000</td>\n",
       "      <td>1805</td>\n",
       "      <td>Narsingi</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>...</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2518 rows × 40 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         Price  Area     Location  No. of Bedrooms  Resale  MaintenanceStaff  \\\n",
       "0      6968000  1340     Nizampet                2       0                 0   \n",
       "1     29000000  3498  Hitech City                4       0                 0   \n",
       "2      6590000  1318    Manikonda                2       0                 0   \n",
       "3      5739000  1295        Alwal                3       1                 0   \n",
       "4      5679000  1145   Kukatpally                2       0                 0   \n",
       "...        ...   ...          ...              ...     ...               ...   \n",
       "2513  11000000  1460     Nacharam                2       1                 9   \n",
       "2514  26000000  1314    Manikonda                2       1                 9   \n",
       "2515  13300000  2625     Madhapur                3       1                 9   \n",
       "2516  10800000  2050  Hitech City                3       0                 9   \n",
       "2517  10400000  1805     Narsingi                3       0                 9   \n",
       "\n",
       "      Gymnasium  SwimmingPool  LandscapedGardens  JoggingTrack  ...  \\\n",
       "0             1             1                  1             1  ...   \n",
       "1             1             1                  1             1  ...   \n",
       "2             1             0                  0             0  ...   \n",
       "3             0             0                  0             0  ...   \n",
       "4             0             0                  1             0  ...   \n",
       "...         ...           ...                ...           ...  ...   \n",
       "2513          9             9                  9             9  ...   \n",
       "2514          9             9                  9             9  ...   \n",
       "2515          9             9                  9             9  ...   \n",
       "2516          9             9                  9             9  ...   \n",
       "2517          9             9                  9             9  ...   \n",
       "\n",
       "      LiftAvailable  BED  VaastuCompliant  Microwave  GolfCourse  TV  \\\n",
       "0                 1    0                1          0           0   0   \n",
       "1                 1    0                1          0           0   0   \n",
       "2                 0    0                0          0           0   0   \n",
       "3                 1    0                0          0           0   0   \n",
       "4                 1    0                0          0           0   0   \n",
       "...             ...  ...              ...        ...         ...  ..   \n",
       "2513              9    9                9          9           9   9   \n",
       "2514              9    9                9          9           9   9   \n",
       "2515              9    9                9          9           9   9   \n",
       "2516              9    9                9          9           9   9   \n",
       "2517              9    9                9          9           9   9   \n",
       "\n",
       "      DiningTable  Sofa  Wardrobe  Refrigerator  \n",
       "0               0     0         0             0  \n",
       "1               0     0         0             0  \n",
       "2               0     0         0             0  \n",
       "3               0     0         0             0  \n",
       "4               0     0         0             0  \n",
       "...           ...   ...       ...           ...  \n",
       "2513            9     9         9             9  \n",
       "2514            9     9         9             9  \n",
       "2515            9     9         9             9  \n",
       "2516            9     9         9             9  \n",
       "2517            9     9         9             9  \n",
       "\n",
       "[2518 rows x 40 columns]"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "housing = pd.read_csv('Hyderabad.csv')\n",
    "housing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Area</th>\n",
       "      <th>No. of Bedrooms</th>\n",
       "      <th>Resale</th>\n",
       "      <th>MaintenanceStaff</th>\n",
       "      <th>Gymnasium</th>\n",
       "      <th>SwimmingPool</th>\n",
       "      <th>LandscapedGardens</th>\n",
       "      <th>JoggingTrack</th>\n",
       "      <th>RainWaterHarvesting</th>\n",
       "      <th>IndoorGames</th>\n",
       "      <th>...</th>\n",
       "      <th>LiftAvailable</th>\n",
       "      <th>BED</th>\n",
       "      <th>VaastuCompliant</th>\n",
       "      <th>Microwave</th>\n",
       "      <th>GolfCourse</th>\n",
       "      <th>TV</th>\n",
       "      <th>DiningTable</th>\n",
       "      <th>Sofa</th>\n",
       "      <th>Wardrobe</th>\n",
       "      <th>Refrigerator</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1340</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3498</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1318</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1295</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1145</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2513</th>\n",
       "      <td>1460</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>...</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2514</th>\n",
       "      <td>1314</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>...</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2515</th>\n",
       "      <td>2625</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>...</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2516</th>\n",
       "      <td>2050</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>...</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2517</th>\n",
       "      <td>1805</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>...</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2518 rows × 38 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      Area  No. of Bedrooms  Resale  MaintenanceStaff  Gymnasium  \\\n",
       "0     1340                2       0                 0          1   \n",
       "1     3498                4       0                 0          1   \n",
       "2     1318                2       0                 0          1   \n",
       "3     1295                3       1                 0          0   \n",
       "4     1145                2       0                 0          0   \n",
       "...    ...              ...     ...               ...        ...   \n",
       "2513  1460                2       1                 9          9   \n",
       "2514  1314                2       1                 9          9   \n",
       "2515  2625                3       1                 9          9   \n",
       "2516  2050                3       0                 9          9   \n",
       "2517  1805                3       0                 9          9   \n",
       "\n",
       "      SwimmingPool  LandscapedGardens  JoggingTrack  RainWaterHarvesting  \\\n",
       "0                1                  1             1                    1   \n",
       "1                1                  1             1                    1   \n",
       "2                0                  0             0                    0   \n",
       "3                0                  0             0                    0   \n",
       "4                0                  1             0                    0   \n",
       "...            ...                ...           ...                  ...   \n",
       "2513             9                  9             9                    9   \n",
       "2514             9                  9             9                    9   \n",
       "2515             9                  9             9                    9   \n",
       "2516             9                  9             9                    9   \n",
       "2517             9                  9             9                    9   \n",
       "\n",
       "      IndoorGames  ...  LiftAvailable  BED  VaastuCompliant  Microwave  \\\n",
       "0               1  ...              1    0                1          0   \n",
       "1               1  ...              1    0                1          0   \n",
       "2               1  ...              0    0                0          0   \n",
       "3               0  ...              1    0                0          0   \n",
       "4               0  ...              1    0                0          0   \n",
       "...           ...  ...            ...  ...              ...        ...   \n",
       "2513            9  ...              9    9                9          9   \n",
       "2514            9  ...              9    9                9          9   \n",
       "2515            9  ...              9    9                9          9   \n",
       "2516            9  ...              9    9                9          9   \n",
       "2517            9  ...              9    9                9          9   \n",
       "\n",
       "      GolfCourse  TV  DiningTable  Sofa  Wardrobe  Refrigerator  \n",
       "0              0   0            0     0         0             0  \n",
       "1              0   0            0     0         0             0  \n",
       "2              0   0            0     0         0             0  \n",
       "3              0   0            0     0         0             0  \n",
       "4              0   0            0     0         0             0  \n",
       "...          ...  ..          ...   ...       ...           ...  \n",
       "2513           9   9            9     9         9             9  \n",
       "2514           9   9            9     9         9             9  \n",
       "2515           9   9            9     9         9             9  \n",
       "2516           9   9            9     9         9             9  \n",
       "2517           9   9            9     9         9             9  \n",
       "\n",
       "[2518 rows x 38 columns]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "features = housing.drop(['Location', 'Price'], axis=1)\n",
    "features"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0        6968000\n",
       "1       29000000\n",
       "2        6590000\n",
       "3        5739000\n",
       "4        5679000\n",
       "          ...   \n",
       "2513    11000000\n",
       "2514    26000000\n",
       "2515    13300000\n",
       "2516    10800000\n",
       "2517    10400000\n",
       "Name: Price, Length: 2518, dtype: int64"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "labels = housing['Price']\n",
    "labels"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Building and training the neural network"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Model: \"sequential_1\"\n",
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "dense_4 (Dense)              (None, 38)                1482      \n",
      "_________________________________________________________________\n",
      "dropout_3 (Dropout)          (None, 38)                0         \n",
      "_________________________________________________________________\n",
      "dense_5 (Dense)              (None, 128)               4992      \n",
      "_________________________________________________________________\n",
      "dropout_4 (Dropout)          (None, 128)               0         \n",
      "_________________________________________________________________\n",
      "dense_6 (Dense)              (None, 64)                8256      \n",
      "_________________________________________________________________\n",
      "dropout_5 (Dropout)          (None, 64)                0         \n",
      "_________________________________________________________________\n",
      "dense_7 (Dense)              (None, 1)                 65        \n",
      "=================================================================\n",
      "Total params: 14,795\n",
      "Trainable params: 14,795\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n"
     ]
    }
   ],
   "source": [
    "# Imports\n",
    "#import numpy as np\n",
    "from tensorflow.keras.models import Sequential\n",
    "from tensorflow.keras.layers import Dense, Dropout\n",
    "#from tensorflow.keras.layers import Dense, Dropout, Activation\n",
    "#from tensorflow.keras.optimizers import SGD\n",
    "\n",
    "# Building the model\n",
    "model = Sequential()\n",
    "model.add(Dense(38, activation='relu', input_shape=(38,)))\n",
    "model.add(Dropout(.2))\n",
    "model.add(Dense(128, activation='relu'))\n",
    "model.add(Dropout(.2))\n",
    "model.add(Dense(64, activation='relu'))\n",
    "model.add(Dropout(.2))\n",
    "model.add(Dense(1))\n",
    "\n",
    "# Compiling the model. The metrics flag is added for the model to report the root mean squared error at each epoch.\n",
    "model.compile(loss = 'mean_squared_error', optimizer='adam', metrics=[keras.metrics.RootMeanSquaredError()])\n",
    "model.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 1/10\n",
      "252/252 [==============================] - 0s 2ms/step - loss: 156452673028096.0000 - root_mean_squared_error: 12508104.0000\n",
      "Epoch 2/10\n",
      "252/252 [==============================] - 0s 2ms/step - loss: 42134430285824.0000 - root_mean_squared_error: 6491104.5000\n",
      "Epoch 3/10\n",
      "252/252 [==============================] - 0s 2ms/step - loss: 34040446976000.0000 - root_mean_squared_error: 5834419.5000\n",
      "Epoch 4/10\n",
      "252/252 [==============================] - 0s 2ms/step - loss: 34078187323392.0000 - root_mean_squared_error: 5837652.5000\n",
      "Epoch 5/10\n",
      "252/252 [==============================] - 0s 2ms/step - loss: 33885654089728.0000 - root_mean_squared_error: 5821138.5000\n",
      "Epoch 6/10\n",
      "252/252 [==============================] - 0s 2ms/step - loss: 34664995618816.0000 - root_mean_squared_error: 5887698.5000\n",
      "Epoch 7/10\n",
      "252/252 [==============================] - 0s 2ms/step - loss: 34479557050368.0000 - root_mean_squared_error: 5871929.5000\n",
      "Epoch 8/10\n",
      "252/252 [==============================] - 0s 2ms/step - loss: 32498731974656.0000 - root_mean_squared_error: 5700766.0000\n",
      "Epoch 9/10\n",
      "252/252 [==============================] - 1s 2ms/step - loss: 33551305146368.0000 - root_mean_squared_error: 5792349.0000\n",
      "Epoch 10/10\n",
      "252/252 [==============================] - 0s 2ms/step - loss: 33920928186368.0000 - root_mean_squared_error: 5824167.5000\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<tensorflow.python.keras.callbacks.History at 0x63c09c610>"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.fit(features, labels, epochs=10, batch_size=10)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Evaluating the model and making predictions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "79/79 [==============================] - 0s 1ms/step - loss: 30640927932416.0000 - root_mean_squared_error: 5535425.0000\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[30640927932416.0, 5535425.0]"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.evaluate(features, labels)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 8851749.],\n",
       "       [23087238.],\n",
       "       [ 8696131.],\n",
       "       ...,\n",
       "       [17321010.],\n",
       "       [13520624.],\n",
       "       [11904336.]], dtype=float32)"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.predict(features)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0        6968000\n",
       "1       29000000\n",
       "2        6590000\n",
       "3        5739000\n",
       "4        5679000\n",
       "          ...   \n",
       "2513    11000000\n",
       "2514    26000000\n",
       "2515    13300000\n",
       "2516    10800000\n",
       "2517    10400000\n",
       "Name: Price, Length: 2518, dtype: int64"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "labels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
